home *** CD-ROM | disk | FTP | other *** search
- /***
- * sendAEPrintDoc.c
- *
- * This hypercard XFCN will send a AE print document command to some target
- * application. The error returned will be returned to the caller.
- *
- * Gordon Watts July '91 Copyright.
- *
- ***/
- #include <HyperXCmd.h>
- #include "hyperUtil.h"
-
- /**
- ** some config defines...
- **/
-
- #define usageString "sendAEPrintDoc <program>"
- #define versionString "sendAEPrintDoc v1.0 Gordon Watts"
- #define badString "This should never be returned! BuG! Bug!"
- #define badParamNumString "Wrong number of parameters. Pass ? to see usage."
- #define badMake "Couldn't make the Apple Event! Bad prog name?"
- #define badSend "Couldn't send the AE!"
- #define goodDone "\p"
- #define badFileList "Couldn't understand your list of files."
- #define badAddP "Couldn't add the file list to the apple event!"
- #define BugOut(error, string) {Str255 theString; \
- done = true; \
- paramPtr -> returnValue = strToHandle(paramPtr, string); \
- NumToStr (paramPtr, error, theString); \
- theString[theString[0]+1] = 0; \
- SetGlobal (paramPtr, (StringPtr) "\ptheAEXError", \
- (Handle) strToHandle (paramPtr, (char *) &(theString[1])));}
-
- /**
- * main
- *
- * Main routine for this xfunction.
- *
- **/
- pascal void main(XCmdPtr paramPtr)
- {
- Boolean done = false;
- TargetID theTarget;
- register int theErr;
- AEAddressDesc targetAddress;
- AppleEvent theAppleEvent, theReplyEvent;
- AEDescList theFileList;
-
-
- /**
- ** Set up default return values
- **/
-
- paramPtr -> returnValue = strToHandle(paramPtr, badString);
- paramPtr -> passFlag = false;
-
- /**
- ** First, do the usage messages: a "!" and a "?".
- **/
-
- if (paramPtr -> paramCount == 1) {
-
- switch (**(paramPtr -> params[0])) {
-
- case '!':
- BugOut (0, versionString);
- break;
-
- case '?':
- BugOut (0, usageString);
- break;
-
- }
- }
-
- /**
- ** Ok. Next job, we had better make sure that we have the
- ** correct number of parameters. Since we need only the
- ** destination application, it had better be just one!
- **/
-
- if ((!done) && (paramPtr -> paramCount != 2)) {
- BugOut (0, badParamNumString);
- }
-
- /**
- ** Next job is to create the apple event with by using our little
- ** home-made subprogram...
- **/
-
- if (!done) {
- Str255 theProgramName;
-
- ZeroToPas (paramPtr, (char *) (*(paramPtr->params[0])), theProgramName);
-
- theErr = AEFromHCProgram (theProgramName, kCoreEventClass,
- kAEPrintDocuments, kAutoGenerateReturnID,
- kAnyTransactionID, &theAppleEvent);
-
- if (theErr != noErr) {
- BugOut (theErr, badMake);
- }
- }
-
- /**
- ** Right-o. Next job is to try and parse the descriptor...
- ** Use a little subroutine to construct the list
- **/
-
- if (!done) {
-
- theErr = makeFileListFmHCF (paramPtr,
- (char *) *(paramPtr->params[1]),
- &theFileList);
- if (theErr != noErr)
- BugOut (theErr, badFileList);
-
- }
-
- /**
- ** Next, add it to the apple event as the single parameter...
- **/
-
- if (!done) {
-
- theErr = AEPutParamDesc (&theAppleEvent, keyDirectObject,
- &theFileList);
-
- if (theErr != noErr)
- BugOut (theErr, badAddP);
- }
-
- /**
- ** Finally, here we send the apple event...
- **/
-
- if (!done) {
- theErr = AESend (&theAppleEvent, &theReplyEvent,
- kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
- kAENormalPriority, kAEDefaultTimeout, 0L, 0L);
- if (theErr != noErr) {
- BugOut (theErr, badSend);
- }
- }
-
- /**
- ** If not done... We are finished...
- **/
-
- if (!done) {
- BugOut (0, goodDone);
- }
- }
-